function angle_to_ball = AngleToBall(P,S,mode)

P_X=P{1}(1);
P_Y=P{1}(2);
P_theta=P{1}(3);
P_num = P{3};

B = S{1};
B_X = B{1}(1);
B_Y = B{1}(2);

angle_to_ball = atan2(B_Y-P_Y,B_X-P_X)/pi*180 - P_theta; % compute the angle to the ball in degrees
angle_to_ball = angle_to_ball - P_theta;

if(angle_to_ball<0)
    while(angle_to_ball<0), angle_to_ball=angle_to_ball+360; end;    %correct the angle
else while(angle_to_ball>360), angle_to_ball=angle_to_ball-360;end;
end

end